/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.semi.fw;

import com.semi.lex.Token;
import com.semi.util.FormatException;
import com.semi.util.StringUtil;
import java.util.Date;

/**
 *
 * @author liaoyq
 */
public class UnCoder extends UnRule {
    public String mName="";
    public String mText="";
    public UnCoder(){
        
    }
    public UnCoder(String name,String text){
        mName = name;
        mText = text;
    }
    public int setProp(String prop,String value) throws FormatException{
        if( value == null ) return 0;
        if( "name".compareToIgnoreCase(prop)==0 ){
            if( value.trim().length()<1 ) return 0;
            mName = value.trim();
        }
        else if( "txt".compareToIgnoreCase(prop)==0 ){
            if( value.trim().length()<1 ) return 0;
            mText = value;
        }
        else if( "enable".compareToIgnoreCase(prop)==0 ) {
            try{
            mEnable = StringUtil.convertToBool(value);
            }catch(Exception e){
                return 0;
            }
        } else return -1;
        return 1;
    }
    public String toCmd(){
        String tmp = "add code name \""+mName+"\" txt \""+mText+"\"";
        if( !mEnable) tmp +=" enable false ";
        return tmp;
    }
    public String dump(){
        return "name["+mName+"] txt["+mText+"] enable["+mEnable+"]";
    }
 
    public boolean match(String s){
        if( !mEnable ) return false;
        return  s.contains(mText);
    }
}
